Skip to content

[Common] MXFP8: Add swizzled-scale fast path for cast-only quantization - #3338

Merged
Oleg-Goncharov merged 4 commits into
NVIDIA:mainfrom
WanZzzzzz:mxfp8-cast-swizzle-main
Aug 11, 2026
Merged

[Common] MXFP8: Add swizzled-scale fast path for cast-only quantization#3338
Oleg-Goncharov merged 4 commits into
NVIDIA:mainfrom
WanZzzzzz:mxfp8-cast-swizzle-main

Conversation

@WanZzzzzz

@WanZzzzzz WanZzzzzz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Description

Produce GEMM-ready scales directly in the specialized MXFP8 cast-only kernels. When GEMM-optimized scales are requested, eligible rowwise and bidirectional casts now write scale inverses directly in the GEMM-swizzled layout.

This avoids separate scale-swizzle kernel launches and reduces intermediate scale-memory traffic. Unsupported shapes and configurations, including noop-aware calls, continue to use the generic implementation to preserve existing behavior.

Irregular but supported shapes are handled by zero-initializing padded scale regions before the specialized kernel writes valid scale values.

Fixes: N/A

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Extend the specialized rowwise cast-only kernel to write scale inverses directly in GEMM-swizzled layout.
  • Add configurable bidirectional cast traits with shared-memory caching and direct swizzled writes for both rowwise and columnwise scales.
  • Route eligible MXFP8 cast-only operations through the specialized kernels for both linear and GEMM-swizzled scale layouts.
  • Preserve the generic fallback for unsupported types and shapes, partial MXFP8 chunks, grid-size limitations, and noop-aware quantization.
  • Zero padded scale regions for irregular GEMM-swizzled tensors to prevent stale values outside the valid scale area.
  • Add C++ coverage comparing direct-swizzle results against the existing linear-cast-then-swizzle reference across multiple shapes and data types.
  • Add PyTorch regression coverage verifying zeroed row-scale padding for irregular bidirectional shape

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Produce GEMM-ready scales directly in the specialized cast-only kernels to avoid separate scale-swizzle launches while preserving generic fallbacks for unsupported shapes.

Signed-off-by: qiyuw <qiyuw@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Aug 10, 2026
@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds GEMM-swizzled scale output to specialized MXFP8 cast-only kernels, avoiding a separate scale-swizzle launch while retaining generic fallbacks.

  • Adds direct rowwise and bidirectional swizzled-scale writes in specialized CUDA kernels.
  • Restricts specialized dispatch by shape, grid size, operation type, and noop state.
  • Adds C++ and PyTorch coverage for scale layout, padding, data types, tensor ranks, and tail cases.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/common/cast/mxfp8/quantize_mxfp8.cuh Extends specialized cast-only dispatch to GEMM-swizzled outputs with shape, grid-size, and noop guards while retaining generic fallbacks.
transformer_engine/common/cast/mxfp8/specialized/quantize_mxfp8.cuh Adds canonical GEMM-swizzled indexing and cached scale flushes for rowwise and bidirectional specialized kernels.
tests/cpp/operator/test_cast_mxfp8.cu Adds byte-exact CUDA coverage comparing direct swizzled output against linear quantization followed by the established swizzle operation.
tests/pytorch/mxfp8/test_mxfp8_quantize_swizzle_fusion.py Adds coverage ensuring padded row-scale slots remain zero for irregular bidirectional tensor shapes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[MXFP8 cast-only quantization] --> B{Supported dtype, shape, grid, and no noop tensor?}
  B -->|Yes: rowwise| C[Specialized rowwise kernel]
  B -->|Yes: bidirectional| D[Specialized bidirectional TMA kernel]
  B -->|No| E[Generic MXFP8 kernel]
  C --> F[Write FP8 data and GEMM-swizzled row scales]
  D --> G[Write rowwise and colwise FP8 data and swizzled scales]
  E --> H[Preserve generic and noop-aware behavior]
  F --> I[GEMM-ready quantized tensor]
  G --> I
  H --> I
Loading

Reviews (3): Last reviewed commit: "merge main and fix conflicts" | Re-trigger Greptile

@Oleg-Goncharov

Copy link
Copy Markdown
Collaborator

/te-ci

Oleg-Goncharov
Oleg-Goncharov previously approved these changes Aug 10, 2026

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ptrendx ptrendx added the 2.19 label Aug 10, 2026
Signed-off-by: qiyuw <qiyuw@nvidia.com>
Signed-off-by: qiyuw <qiyuw@nvidia.com>
@Oleg-Goncharov

Copy link
Copy Markdown
Collaborator

/te-ci

@Oleg-Goncharov
Oleg-Goncharov self-requested a review August 11, 2026 11:12

@Oleg-Goncharov Oleg-Goncharov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Pipeline #62101472 passed without errors.

@Oleg-Goncharov Oleg-Goncharov changed the title mxfp8: add swizzled-scale fast path for cast-only quantization [Common] MXFP8 add swizzled-scale fast path for cast-only quantization Aug 11, 2026
@Oleg-Goncharov Oleg-Goncharov changed the title [Common] MXFP8 add swizzled-scale fast path for cast-only quantization [Common] MXFP8: Add swizzled-scale fast path for cast-only quantization Aug 11, 2026
@Oleg-Goncharov
Oleg-Goncharov merged commit 07e281f into NVIDIA:main Aug 11, 2026
39 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.19 community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants